/**
 * Copyright (C), 2015-2019, XXX有限公司
 * FileName: GoldenLogoutHandler
 * Author:   zhouheng
 * Date:     2019/6/23 20:30
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.zhouh.golden.security.handler;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.session.SessionRegistry;
import org.springframework.security.web.authentication.logout.LogoutHandler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 〈一句话功能简述〉<br> 
 * 〈配置登出处理器，解决登出后 principals 中还存在相应的 sessionInformation 的问题〉
 *
 * @author zhouheng
 * @create 2019/6/23
 * @since 1.0.0
 */
public class GoldenLogoutHandler implements LogoutHandler {
    private SessionRegistry sessionRegistry;

    @Override
    public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
        String sessionId = request.getRequestedSessionId();
        if (sessionId != null) {
            sessionRegistry.removeSessionInformation(sessionId);
        }
    }

    public SessionRegistry getSessionRegistry() {
        return sessionRegistry;
    }

    public void setSessionRegistry(SessionRegistry sessionRegistry) {
        this.sessionRegistry = sessionRegistry;
    }

}